DotNet Example: Working with Streams

Description

Occasionally a .NET function will require that you pass or receive a stream as a parameter. This example shows how to create a stream to upload a file.

To upload a file using a stream, you need to open the file and pass a stream to a function. In the example below, we create an instance of System::IO::FileStream by calling the static function System::IO::File::Open(), passing it the full path to the file and an enumerated type that requests the file be opened in read-only mode. Once the function has uploaded the data, we call Dispose() to release the Windows file handle.

Stripe::StripeConfiguration.SetApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2")

dim Service as Stripe::StripeFileUploadService 
Source = "c:\temp\helloworld.pdf";

dim Stream as System::IO::FileStream = System::IO::File::Open(Source, System::IO::FileMode::Open)

UploadResult = Service.Create(Source, Stream, Stripe::StripeFilePurpose::DisputeEvidence)

' Dispose the stream to make sure it is closed and handles are released
Stream.dispose()

The base type of a stream is System::IO::Stream. There are a number of implementations of streams. In-memory and file streams are two examples. For more information on streams, see System.IO.Stream.

See Also